package kk.service.impl;

import kk.dao.UserDao;
import kk.dao.impl.UserDaoImpl;
import kk.domain.User;
import kk.service.UserService;

public class UserServiceImpl implements UserService {
    private UserDao userDao=new UserDaoImpl();

    /**
     * 注册功能
     * @param user
     * @return
     */
    @Override
    public boolean regist(User user) {
        //先判断用户名是否已经存在
        User existUser = userDao.queryUserByUsername(user.getUsername());
        if (existUser==null){
            //可以注册
            userDao.savaUser(user);
            return true;
        }else {
            //不可以注册
            return false;
        }
    }

    @Override
    public User login(User user) {
        User loginUser = userDao.queryUserByUsernameAndPassword(user.getUsername(), user.getPassword());
        if (loginUser==null){
            return null;
        }else {
            return user;
        }
    }

    @Override
    public boolean exitUsername(String username) {
        User user = userDao.queryUserByUsername(username);
        if (user!=null){
            return true;
        }else {
            return false;
        }
    }


}
